package com.zhkj.shixi.tvplayer.VideoPlayer;

import android.graphics.PixelFormat;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;

import com.zhkj.shixi.tvplayer.MyMediaPlayer;

/**
 * Created by suqiuyu on 19-8-15.
 */

public class PlayerView implements SurfaceHolder.Callback {
    private SurfaceView mSurfaceView;
    private SurfaceHolder mSurfaceHolder;
    private MyMediaPlayer mPlayer;

    public PlayerView(SurfaceView surfaceView, MyMediaPlayer mediaPlayer){
        mSurfaceView = surfaceView;
        mSurfaceHolder = mSurfaceView.getHolder();
        mSurfaceHolder.addCallback(this);
        mPlayer = mediaPlayer;
        //mService.setDisplay(mSurfaceHolder);
    }
    public SurfaceHolder getHolder() {
        return mSurfaceHolder;
    }

    public SurfaceView getSurfaceView() {
        return mSurfaceView;
    }

    @Override
    public void surfaceCreated(SurfaceHolder holder) {
        //Log.i("surfaceCreated: ", "surfaceCreated: ");
        mSurfaceView.setZOrderOnTop(true);
        mSurfaceView.setZOrderMediaOverlay(true);
        mSurfaceHolder.setFormat(PixelFormat.TRANSLUCENT);
    }

    @Override
    public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
        Log.i("surfaceChanged: ", "surfaceChanged: ");
        mPlayer.setDisplay(holder);
    }

    @Override
    public void surfaceDestroyed(SurfaceHolder holder) {

    }
}
